#!/bin/bash
# 计算 120 秒内 $1 每秒IO次数

INTERVAL=120

read rx_init tx_init < <(cat /proc/diskstats|grep $1|awk '{print $4,$8}')

sleep ${INTERVAL}s

read rx_end tx_end < <(cat /proc/diskstats|grep $1 |awk '{print $4,$8}')

now=$(date '+%Y-%m-%d %H:%M:%S')

rx_diff=$((rx_end - rx_init))
tx_diff=$((tx_end - tx_init))
rx_rate=$(echo "scale=4; $rx_diff / $INTERVAL" | bc)
tx_rate=$(echo "scale=4; $tx_diff / $INTERVAL" | bc)

echo $now
echo "RX: $rx_rate io/s"
echo "TX: $tx_rate io/s"
